<?php
/**
 * File: Category.php
 * User: Mr.Yang
 * Date: 2025/3/22 0022
 * Time: 11:30
 * Note:
 */

namespace app\home\controller;


use app\admin\model\Book;
use app\admin\model\Category as CategoryModel;

class Category extends Base
{
    /**
     * Note: 图书分类列表
     * User: Mr.Yang
     * @param int $catid
     * @return mixed
     */
    public function index($catid = 0)
    {
        $category = CategoryModel::where("is_show", "=", 1)->order('sort', 'asc')->select()->toArray();
        $where[] = ['status', '=', 1];
        if ($catid) {
            $where[] = ['catid', '=', $catid];
        }
        //计算总数
        $book = Book::where($where)->order('id', 'desc')->paginate();
        $page = $book->render();
        $this->assign('category', $category);
        $this->assign('catid', $catid);
        $this->assign('book', $book);
        $this->assign('page', $page);
        return $this->fetch();
    }
}